package com.situ.sys.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.sys.entity.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.sys.service.SysMightService;
import com.situ.sys.entity.SysMight;
import com.situ.util.*;

import java.util.List;

/**
 * SysMight的路由接口服务
 * 
 * @author 
 *
 */
@RestController
public class SysMightController {

	/** SysMightService服务 */
	@Autowired
	private SysMightService sysMightService;
	
	/**
	 * 查询所有SysMight数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "querySysMight", produces = {"application/json;charset=UTF-8"})
	public ResponseData find(SysMight value) {

		return ResponseData.ok().putDataValue("list",sysMightService.find(value));
	}
	
	/**
	 * 通过id查询SysMight数据的方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "querySysMightById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData findOne(@PathVariable(name="id") Integer id) {
		 return ResponseData.ok().putDataValue("obj",sysMightService.findOne(id));
	}
	
	/**
	 * 插入SysMight属性不为空的数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "saveSysMight")
	public ResponseData save(SysMight value) {
		return ResponseData.ok().putDataValue("obj", sysMightService.saveNotNull(value));
	}
	
	/**
	 * 更新SysMight属性不为空的数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "updateSysMight", produces = {"application/json;charset=UTF-8"})
	public ResponseData update(SysMight value) {
		return ResponseData.ok().putDataValue("obj",sysMightService.updateNotNullById(value));
	}

	/**
	 * 通过id删除SysMight数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delSysMightById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delete(@PathVariable(name="id") Integer id) {
		return ResponseData.ok().putDataValue("obj",sysMightService.deleteById(id));
	}

	@RequestMapping(value = "selectallrolebymight", produces = {"application/json;charset=UTF-8"})
	public ResponseData selectallrolebymight(Integer id){
		return ResponseData.ok().putDataValue("obj",sysMightService.selectallrolebymight(id));
	}

	@RequestMapping(value = "deletesys_role_rightbyrid/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData deletesys_role_rightbyrid(@PathVariable(name="id") Integer id) {
		sysMightService.deletesys_role_rightbyrid(id);
		return ResponseData.ok();
	}

	@RequestMapping("insertsys_role_right")
	public ResponseData insertsys_role_right(Integer roleid,Integer value){
		System.out.println(roleid);
		sysMightService.insertsys_role_right(roleid, value);
		return ResponseData.ok();
	}

	@RequestMapping("querymighttype")
	public ResponseData querymighttype(){
		return ResponseData.ok().putDataValue("typelist", sysMightService.querymighttype());
	}

	@RequestMapping("selectSysMightBylike")
	public ResponseData selectSysMightBylike(SysMight sm,
						 @RequestParam(defaultValue ="1", required = false) int startPage ,
						 @RequestParam(defaultValue = "15",required = false) int PageSize){
		PageHelper.startPage(startPage,PageSize );
		List<SysMight> list = sysMightService.selectSysMightBylike(sm);
		PageInfo pageInfo=new PageInfo(list,5);
		return ResponseData.ok().putDataValue("pageInfo",pageInfo);
	}
}
